package org.jluzhCS.mylogin.action;

import org.jluzhCS.mylogin.domain.User;
import org.jluzhCS.mylogin.service.UserService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class loginAction implements Action {

	private User user;
	
	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String execute() throws Exception {
		String ADMIN = "admin";
		String CUSTOMER = "customer";
		UserService us = new UserService();
		Integer id = us.ValidLogin(user);
		ActionContext.getContext().getSession().put("user", user);
        if(id>0)
        {
        	if(user.getType().equals(ADMIN))
        		return ADMIN;
        	else
        		return CUSTOMER;
        }
        return ERROR;
	}


}
